// Fill out your copyright notice in the Description page of Project Settings.

#include "Isalong2.h"
#include "CGameManager.h"

ACGameManager* ACGameManager::_gameManager = nullptr;

// Sets default values
ACGameManager::ACGameManager()
{	
	_gameManager = this;
 	// Set this actor to call Tick() every frame.  You can turn this off to improve performance if you don't need it.
	PrimaryActorTick.bCanEverTick = true;

	InitConsole();
}

// Called when the game starts or when spawned
void ACGameManager::BeginPlay()
{
	Super::BeginPlay();
	
}

// Called every frame
void ACGameManager::Tick( float DeltaTime )
{
	Super::Tick( DeltaTime );

}

void ACGameManager::InitConsole()
{
	if (GlobalConfig::__showConsole__)
	{
		AllocConsole();
		freopen("CONOUT$", "w+t", stdout);
		freopen("CONIN$", "r+t", stdin);
		system("cls");
		cout << "Console Window for testing and debuging:" << endl;
		cout << "\tIsAlong:" << endl;
		cout << "\t" << GlobalConfig::__version__ << endl;
	}
}

void ACGameManager::WriteLine(char * str)
{
	cout << str << endl;
}

void ACGameManager::WriteLine(int data)
{
	cout << data << endl;
}

void ACGameManager::WriteLine(void * ptr)
{
	cout << ptr << endl;
}

void ACGameManager::WriteLine(float data)
{
	cout << data << endl;
}

void ACGameManager::WriteScreen(int id, int data)
{
	char str[10];
	sprintf(str, "%d", data);
	GEngine->AddOnScreenDebugMessage(id, 1, FColor::Blue, str);
}

void ACGameManager::WriteScreen(int id, FString data)
{
	GEngine->AddOnScreenDebugMessage(id,1, FColor::Blue, data);
}

void ACGameManager::WriteScreen(int id, FVector data)
{
	GEngine->AddOnScreenDebugMessage(id, 1, FColor::Blue, data.ToString());
}

void ACGameManager::WriteScreen(int id, FVector2D data)
{
	GEngine->AddOnScreenDebugMessage(id, 1, FColor::Blue, data.ToString());
}

void ACGameManager::CloseConsole()
{
	if (GlobalConfig::__showConsole__)
	{
		fclose(stdout);
		fclose(stdin);
		FreeConsole();
	}
}





